package com.xiyuan.view;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

import com.xiyuan.entity.Huiyuan;

public class ExcelView extends AbstractExcelView {

	@Override
	@SuppressWarnings("unchecked")
	protected void buildExcelDocument(Map<String, Object> model, HSSFWorkbook workbook, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		List<Huiyuan> hys =(List<Huiyuan>) model.get("huiyuans");
		response.setHeader("Content-Disposition", "attachment;filename=a.xls");
		
		HSSFSheet sheet = workbook.createSheet("list");
		sheet.setDefaultColumnWidth(12);

		HSSFCell cell = getCell(sheet, 0, 0);
		setText(cell, "Spring Excel test");

		HSSFCellStyle dateStyle = workbook.createCellStyle();
		// dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("mm/dd/yyyy"));
		cell = getCell(sheet, 1, 0);
		cell.setCellValue("日期：2008-10-23");
		// cell.setCellStyle(dateStyle);
		getCell(sheet, 2, 0).setCellValue("测试1");
		getCell(sheet, 2, 1).setCellValue("测试2");

		HSSFRow sheetRow = sheet.createRow(3);
		for (int i = 0; i < hys.size(); i++) {
			sheetRow.createCell(i).setCellValue(hys.get(i).getAihao());
		}

	}

}
